package com.oracle.tutorial.concurrency;

public class SleepMessages {
	String[] importantInfo;
    public static void main(String args[])
    {
        try {
			new SleepMessages().print01();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
    }
    public SleepMessages() {
    	importantInfo = new String[4];
    	importantInfo[0] = "Mares eat oats";
    	importantInfo[1] = "Does eat oats";
    	importantInfo[2] = "Little lambs eat ivy";
    	importantInfo[3] = "A kid will eat ivy too";
    }
    
    public void print01() throws InterruptedException  {
    	for (int i = 0; i < importantInfo.length; i++) {
			// Pause for .5 seconds
			Thread.sleep(500);
			// Print a message
			System.out.println(importantInfo[i]);
		}
    }
    
    public void print02() {
    	for (int i = 0; i < importantInfo.length; i++) {
    	    try {
    	        Thread.sleep(500);
    	    } catch (InterruptedException e) {
    	        // We've been interrupted: no more messages.
    	        return;
    	    }
    	    System.out.println(importantInfo[i]);
    	}
    }
}
